<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input type="text">
    <button>百度一下</button>

    <ul>

    </ul>

    <script>

        // 
        const oKw = document.querySelector('input');
        const oBtn = document.querySelector('button');
        const oUl = document.querySelector('ul');

        oBtn.onclick = function () {
            const kw = oKw.value;

            // 请求数据
            const oS = document.querySelector('#s');
            if (oS) {
                // oS.src = `https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=${kw}`; // 不会请求
                oS.remove();
            }
            const oScript = document.createElement('script');
            oScript.id = 's';
            oScript.src = `https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=${kw}`;
            document.body.appendChild(oScript);

        }


        var baidu = {
            sug: function (data) {
                console.log(data);
                const { s } = data;
                if (s) {
                    let html = '';
                    s.forEach(v => {

                        html += `
                            <li>
                                <a href="https://www.baidu.com/s?wd=${v}">${v}</a>
                            </li>
                        `
                    })
                    oUl.innerHTML = html;
                }

            }
        }


        // window.baidu.sug();

    </script>




</body>

</html>